from pylab import *
from rapameters import *
from oscillator import *
from copy import *
from time import *
from wave import Wave
from node import Node

TIME = 240;
DT   = 1;

print "Time: ", TIME, " h"
print "Resolution: ", DT, "h"
print "----------------------------------------------------------"

rarray = RapameterArray()

'''
if(str(sys.argv[1] == 'help')):
		print "usage: rap.py (rp) (rm) (qp) (qm) (k) (tau) (n) (m)"
		quit()
elif(str(sys.argv[1] == 'iterate')):
    iterate()
'''


if len(sys.argv) == 9:
	rarray.append(Rapameter("rp",   "Production rate (P)",                float(sys.argv[1]),False,True,0.1));
	rarray.append(Rapameter("rm",   "Production rate (M)",                float(sys.argv[2]),False,True,0.1));
	rarray.append(Rapameter("qp",   "Degradation rate (P)",               float(sys.argv[3]),True,True,0.1));
	rarray.append(Rapameter("qm",   "Degradation rate (M)",               float(sys.argv[4]),True,True,0.1));
	rarray.append(Rapameter("k",    "Scaling constant",                   float(sys.argv[5]),False,True,0.1));
	rarray.append(Rapameter("tau",  "Transcription-translation delay",    float(sys.argv[6]),True,True,1));
	rarray.append(Rapameter("n",    "Hill coefficient",                   float(sys.argv[7]),True,True,1));
	rarray.append(Rapameter("m",    "Non-linearity",                      float(sys.argv[8]),True,True,1));

elif len(sys.argv) == 1:
	rarray.append(Rapameter("rp",   "Production rate (P)",                1.9,True,True,0.1));
	rarray.append(Rapameter("rm",   "Production rate (M)",                0.5,True,True,0.1));
	rarray.append(Rapameter("qp",   "Degradation rate (P)",               0.4,True,True,0.1));
	rarray.append(Rapameter("qm",   "Degradation rate (M)",               0.4,True,True,0.1));
	rarray.append(Rapameter("tau",  "Transcription-translation delay",    10.0,True,True,0.1));
	rarray.append(Rapameter("m",    "Non-linearity",                      3.5,True,True,0.1));
	rarray.append(Rapameter("n",    "Hill coefficient",                   6.0,True,True,2.1));
	rarray.append(Rapameter("k",    "Scaling constant",                   1.0,True,True,0.1));
	


	for i in range(20):
		rarray['n'].increase();
		osc = Oscillator(rarray,TIME,DT);
		osc.run();
		v = osc.get_vals();
		t = osc.get_times();
		plot(t,v,linewidth=1.0);
		draw();		
		#slee(1);
				

	show()	
	quit()

elif len(sys.argv) == 1:
	if(str(sys.argv[1] == 'help')):
		print "usage: rap.py (rp) (rm) (qp) (qm) (k) (tau) (n) (m)"
		quit()
  

		
else:
	print "usage: rap.py (rp) (rm) (qp) (qm) (k) (tau) (n) (m)"
	quit()

'''
rm  = 1.0;
k   = 1;
n   = 2.0;
qm  = 0.21;
rp  = 1;
m   = 3.0;
qp  = 0.21;
rarray.append(Rapameter("rp",   "Production rate (P)",                1.9,True,True,0.1));
rarray.append(Rapameter("rm",   "Production rate (M)",                0.5,True,True,0.1));
rarray.append(Rapameter("qp",   "Degradation rate (P)",               0.4,True,True,0.1));
rarray.append(Rapameter("qm",   "Degradation rate (M)",               0.4,True,True,0.1));
rarray.append(Rapameter("tau",  "Transcription-translation delay",    10.0,True,True,0.1));
rarray.append(Rapameter("k",    "Hill coefficient",                   1.0,True,True,0.1));
rarray.append(Rapameter("m",    "Non-linearity",                      3.5,True,True,0.1));
rarray.append(Rapameter("n",    "Non-linearity",                      6.0,True,True,0.1));
'''
rarray.printOut()
print "----------------------------------------------------------"
print ""
#print rarray
#root = Node(None,deepcopy(rarray),TIME,DT);
#root.run()


#koliko oscilacij na uro
#wav = Wave(9.99689001217,0.0358974358974,TIME,DT)
wav = Wave(29,0.038095238095238099,TIME,DT)
osc = Oscillator(rarray,TIME,DT);
osc.run()


print 'amp: ',osc.get_amp();
print 'frq: ', osc.get_frq();
print 'time up: ',osc.get_tim_up();
print 'time down: ',osc.get_tim_down();


t = osc.get_times();
v1 =  osc.get_vals();
v2 = wav.get_vals();
plot(t, v1, linewidth=1.0)
#plot(t, v2, linewidth=1.0)

xlabel('time')
ylabel('vals')
xticks(range(0,TIME,int(TIME*0.1)))
title(str(osc))
grid(True)
savefig('out/'+rarray.get_fname()+'.png',format='png')
show()
  
      
